# -*- coding: utf-8 -*-

# 引入http response
from django.http import HttpResponse
from django.http import JsonResponse
import json
# 引入鉴权模块
from django.contrib.auth import login, authenticate
from django.contrib.auth.models import User
# 引入token模块
import vue_app.utils.token as Token
# 引入鉴权装饰器
from vue_app.utils.auth_permission import auth_permission_require

# 其他模块
import time

# 命令行api
@auth_permission_require('')
def cmdline_api(request):
    params = json.loads(request.body)
    print(params)
    res = {"code": 20000}
    # todo: 这里先只返回前端的命令行
    date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    data = "[{}]".format(date) # 日期
    level= "[INFO]"            # 等级
    tag  = "[SEND]"            # 收发标志
    tar  = "[{}]".format(params.get("deviceId", "None"))
    cmd  = params.get("cmd", "")
    # todo: MQTT 返回的数据用其他形式实现
    pass
    # 添加
    res.update({
        "data": data,
        "level": level,
        "tag": tag,
        "tar": tar,
        "cmd": cmd
    })
    return JsonResponse(res)